package com.xuxin.nantai.base;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.blankj.utilcode.util.ToastUtils;
import com.xuxin.nantai.bean.BaseBean;

import butterknife.ButterKnife;

/**
 * Created by xu_xin
 * Created on 2020.06.05
 */
public abstract class BaseFragment extends Fragment implements View.OnClickListener {

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater,
                             @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View view = setContentView(inflater, container);
        ButterKnife.bind(this, view);
        initView();
        initData();
        return view;
    }

    public abstract View setContentView(@NonNull LayoutInflater inflater,
                                        @Nullable ViewGroup container);

    public abstract void initView();

    public abstract void initData();

    public abstract void onComplete();

    public void onError(BaseBean baseBean) {
        if (null != baseBean) {
            ToastUtils.showShort(baseBean.getMessage());
        } else {
            ToastUtils.showShort("网络连接异常");
        }
        onComplete();
    }
}